﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Collections.Specialized;

namespace JMT.Data
{
    public sealed class JClassContainer : IJClassContainer
    {
        public event NotifyCollectionChangedEventHandler JClassCollectionChanged;

        ObservableCollection<JClass> ClassCollection { get; set; }

        public JClassContainer()
        {
            ClassCollection = new ObservableCollection<JClass>();
            ClassCollection.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(ClassCollection_CollectionChanged);
        }

        void ClassCollection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (JClassCollectionChanged != null)
            {
                JClassCollectionChanged(sender, e);
            }
        }

        public void AddClass(JClass jClass)
        {
            ClassCollection.Add(jClass);
        }

        public void RemoveClass(JClass jClass)
        {
            ClassCollection.Remove(jClass);
        }

        public JClass GetClass(Guid id)
        {
            foreach (var jClass in ClassCollection)
            {
                if (jClass.Id == id)
                {
                    return jClass;
                }
            }
            return null;
        }

        public List<JClass> ToClassList()
        {
            return ClassCollection.ToList();
        }
    }
}
